package com.ship.dispatch.service.orderPay.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ship.dispatch.bean.orderPay.QueryFundManageInfo;
import com.ship.dispatch.bean.orderPay.SpFundManage;
import com.ship.dispatch.bean.orderPay.SpFundPayManageDetail;
import com.ship.dispatch.mapper.orderPay.SpFundPayManageDetailMapper;
import com.ship.dispatch.service.orderPay.SpFundPayManageDetailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <b>SpFundPayManageDetailServiceImpl</b>
 *
 * @description: SpFundPayManageDetailServiceImpl <br>
 * @date: 2024/8/16 11:58 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class SpFundPayManageDetailServiceImpl extends ServiceImpl<SpFundPayManageDetailMapper, SpFundPayManageDetail> implements SpFundPayManageDetailService {
    private static final Logger logger = LoggerFactory.getLogger(SpFundPayManageDetailServiceImpl.class);


    @Override
    public List<QueryFundManageInfo> queryCountFundTotal(List<SpFundManage> fundManageList) {
        List<QueryFundManageInfo> list = new ArrayList<>();
        fundManageList.forEach(item -> {
            Integer total = baseMapper.queryPayNumber(item.getId());
            QueryFundManageInfo queryFundManageInfo = new QueryFundManageInfo();
            queryFundManageInfo.setId(item.getId());
            if (total != null){
                if (item.getAccountBalance().compareTo(new BigDecimal(total)) >= 0){
                    queryFundManageInfo.setAccountBalance(item.getPayAmount().subtract(new BigDecimal(total)));
                    list.add(queryFundManageInfo);
                }
            }else {
                queryFundManageInfo.setAccountBalance(item.getPayAmount());
                list.add(queryFundManageInfo);
            }

        });
        return list;
    }
}
